package com.pdg.mcplugin.common;

import java.util.ArrayList;

public class ArgumentList extends ArrayList<String>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8284082633990480859L;
	private static final int ARGUMENT_INDEX_ZERO = 0;
	private static final int DEFAULT_POP_COUNT = 1;
	private static final String DEFAULT_GLUE = " ";

	public ArgumentList(String[] theArgumentList){
		super(theArgumentList.length);
		for(int index=0;index<theArgumentList.length;++index){
			add(theArgumentList[index]);
		}
	}
	public String pop() throws StackOverflowError{
		return pop(DEFAULT_POP_COUNT,DEFAULT_GLUE);
	}
	public String pop(String theGlue) throws StackOverflowError{
		return pop(DEFAULT_POP_COUNT,theGlue);
	}
	public String pop(int theCount){
		return pop(theCount,DEFAULT_GLUE);
	}
	public String pop(int theCount,String theGlue) throws StackOverflowError{
		String result = null;
		while(theCount>0){
			if(isEmpty()) throw new StackOverflowError();
			if(result==null){
				result = get(ARGUMENT_INDEX_ZERO);
			}else{
				result += theGlue;
				result += get(ARGUMENT_INDEX_ZERO);
			}
			remove(ARGUMENT_INDEX_ZERO);
			theCount--;
		}
		return result;
	}
	public String popAll(){
		return pop(size());
	}
	public String popAll(String theGlue){
		return pop(size(),theGlue);
	}
}
